package com.xqb.modules.controller.exam;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.ExaExamDetail;
import com.xqb.modules.service.IExaExamDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 考试或测验详情Controller
 *
 * @author ruoyi
 * @date 2024-10-18
 */
@RestController
@RequestMapping("/exam/exam_detail")
public class ExaExamDetailController extends BaseController {
    @Autowired
    private IExaExamDetailService exaExamDetailService;

    /**
     * 查询考试或测验详情列表
     */
    @PreAuthorize("@ss.hasPermi('exam:exam_detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExaExamDetail exaExamDetail) {
        startPage();
        List<ExaExamDetail> list = exaExamDetailService.selectExaExamDetailList(exaExamDetail);
        return getDataTable(list);
    }

    /**
     * 导出考试或测验详情列表
     */
    @PreAuthorize("@ss.hasPermi('exam:exam_detail:export')")
    @Log(title = "考试或测验详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExaExamDetail exaExamDetail) {
        List<ExaExamDetail> list = exaExamDetailService.selectExaExamDetailList(exaExamDetail);
        ExcelUtil<ExaExamDetail> util = new ExcelUtil<ExaExamDetail>(ExaExamDetail.class);
        util.exportExcel(response, list, "考试或测验详情数据");
    }

    /**
     * 获取考试或测验详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:exam_detail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(exaExamDetailService.selectExaExamDetailById(id));
    }

    /**
     * 新增考试或测验详情
     */
    @PreAuthorize("@ss.hasPermi('exam:exam_detail:add')")
    @Log(title = "考试或测验详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExaExamDetail exaExamDetail) {
        return toAjax(exaExamDetailService.insertExaExamDetail(exaExamDetail));
    }

    /**
     * 修改考试或测验详情
     */
    @PreAuthorize("@ss.hasPermi('exam:exam_detail:edit')")
    @Log(title = "考试或测验详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExaExamDetail exaExamDetail) {
        return toAjax(exaExamDetailService.updateExaExamDetail(exaExamDetail));
    }

    /**
     * 删除考试或测验详情
     */
    @PreAuthorize("@ss.hasPermi('exam:exam_detail:remove')")
    @Log(title = "考试或测验详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(exaExamDetailService.deleteExaExamDetailByIds(ids));
    }
}
